package com.sys.servlet.mgr.course;

import com.sys.entity.Course;
import com.sys.pojo.JsonResult;
import com.sys.service.CourseService;
import com.sys.utils.WriteJson;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet(urlPatterns = "/mgr/course/list")
public class listServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String cname = req.getParameter("cname");
        String tid = req.getParameter("tid");
        CourseService courseService = new CourseService();
        JsonResult jr = new JsonResult();
        try {
            List<Course> list = courseService.showList(cname, tid);
            jr.setCode(0);
            jr.setData(list);
        } catch (Exception e) {
            e.printStackTrace();
            jr.setCode(500);
            jr.setMsg("查询发生错误");
        }
        WriteJson.write(resp,jr);
    }
}
